<?php
class AjaxUserInformer_Form_Admin_General extends Engine_Form {
	
	protected $ajaxui_fields;
	
	public function init() {
		$settings = Engine_Api::_ ()->getApi ( 'settings', 'MsepCore' );
		
		$this->ajaxui_fields = 0;
		
		$this->setTitle ( 'General Settings' )->setDescription ( 'These settings affect to the content and behavior of the user information popups.' );
		
		$mouse_over = $this->createElement ( 'radio', 'ajaxui_mouse_over', array ('label' => 'Mouse Over', 'description' => 'Do you want to view user information popups on mouse over link, image or both?', 'multiOptions' => array (0 => 'Link', 1 => 'Image', 2 => 'Both' ), 'value' => array_keys ( array (0 => 'Link', 1 => 'Image', 2 => 'Both' ) ) ) )->setValue ( $settings->ajaxui->mouse_over );
		
		$this->addElement ( $mouse_over );
		
		$new = $this->createElement ( 'Heading', 'fields_title', array ('description' => 'Select below all those profile fields you want to include in user information popups. Below is a list of profile fields seperated by Profile Types.', 'label' => 'User Information' ) );
		
		$new->getDecorator ( 'HtmlTag2' )->setOption ( 'style', 'padding-bottom: 5px;' );
		
		$this->addElement ( $new );
	}
	
	public function end($options) {
		$settings = Engine_Api::_ ()->getApi ( 'settings', 'MsepCore' );
		
		foreach ( $options as $heading => $fields ) {
			$new = $this->createElement ( 'MultiCheckbox', "ajaxui_user_fields_{$this->ajaxui_fields}", array ('label' => '', 'description' => $heading, 'multiOptions' => $fields, 'value' => array_keys ( $fields ) ) );
			
			$user_fields = json_decode ( $settings->ajaxui->user_fields );
			
			$new->setValue ( $user_fields );
			
			if ($this->ajaxui_fields > 0)
				$new->getDecorator ( 'HtmlTag2' )->setOption ( 'style', 'border: 0; padding-top: 0;' );
			else
				$new->getDecorator ( 'HtmlTag2' )->setOption ( 'style', 'border-top: 0; padding-top: 0;' );
			
			$new->getDecorator ( 'Description' )->setOption ( 'style', 'font-weight: bold;' );
			
			$this->addElement ( $new );
			
			$this->ajaxui_fields ++;
		}
		
		$user_thumbnail = $this->createElement ( 'radio', 'ajaxui_user_thumbnail', array ('label' => 'User Thumbnail', 'description' => 'Do you want to view user thumbnail in user information popups?', 'multiOptions' => array (0 => 'No', 1 => 'Yes' ), 'value' => array_keys ( array (0 => 'No', 1 => 'Yes' ) ) ) )->setValue ( $settings->ajaxui->user_thumbnail );
		
		$this->addElement ( $user_thumbnail );
		
		$user_mutual = $this->createElement ( 'radio', 'ajaxui_user_mutual', array ('label' => 'Mutual Friends', 'description' => 'Do you want to view mutual friends in user information popups?', 'multiOptions' => array (0 => 'No', 1 => 'Yes' ), 'value' => array_keys ( array (0 => 'No', 1 => 'Yes' ) ) ) )->setValue ( $settings->ajaxui->user_mutual );
		
		$this->addElement ( $user_mutual );
		
		$user_button_friend = $this->createElement ( 'radio', 'ajaxui_user_button_friend', array ('label' => 'Add to Friends', 'description' => 'Do you want to include "Add to Friends" button in user information popups?', 'multiOptions' => array (0 => 'No', 1 => 'Yes' ), 'value' => array_keys ( array (0 => 'No', 1 => 'Yes' ) ) ) )->setValue ( $settings->ajaxui->user_button_friend );
		
		$this->addElement ( $user_button_friend );
		
		$user_button_message = $this->createElement ( 'radio', 'ajaxui_user_button_message', array ('label' => 'Send Message', 'description' => 'Do you want to include "Send Message" button in user information popups?', 'multiOptions' => array (0 => 'No', 1 => 'Yes' ), 'value' => array_keys ( array (0 => 'No', 1 => 'Yes' ) ) ) )->setValue ( $settings->ajaxui->user_button_message );
		
		$this->addElement ( $user_button_message );
		
		// init submit
		$this->addElement ( 'Button', 'submit', array ('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true ) );
	}

}